package com.example.minemodule.model;

import android.text.TextUtils;

import androidx.lifecycle.MutableLiveData;

import com.examination.mlib.constants.UserInfoConstants;
import com.example.minemodule.entity.OrderEntity;
import com.example.minemodule.entity.PersonCenterEntity;
import com.examination.mlib.bean.UserActionEntity;
import com.example.minemodule.net.MineApiService;
import com.yilijk.base.base.BaseRepositoryImpl;
import com.yilijk.base.network.RequestParams;
import com.yilijk.base.network.bean.Resource;
import com.yilijk.base.network.core.RetrofitManager;
import com.yilijk.base.network.https.HttpCallBack;
import com.yilijk.base.network.https.HttpUtils;
import com.yilijk.base.utils.SharedPreferencesUtils;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by SHICHENG
 * on 2021/10/25.
 */
public class MineModel extends BaseRepositoryImpl {

    /**
     * 获取用户头像
     */
    public String getAvator(String avator){
        if (SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_imgUrl, null) != null){
            avator = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_imgUrl, null);
        }else if (SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_imgUrl, null) != null){
            avator = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_imgUrl, null);
        }
        return avator;
    }
    /**
     * 获取用户昵称
     */
    public String getName(){
        String name = "";
        if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_nickName, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_nickName, null);
        }else if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_nickName, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_nickName, null);
        }else if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_nickName, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_nickName, null);
        }else if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_mobile, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_mobile, null);
            name = name.substring(0,3)+"****"+name.substring(7);
        }else if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.account_mobile, null);
            name = name.substring(0,3)+"****"+name.substring(7);
        }else if (!TextUtils.isEmpty(SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_mobile, null))){
            name = SharedPreferencesUtils.getInstance().getString(UserInfoConstants.passport_mobile, null);
            name = name.substring(0,3)+"****"+name.substring(7);
        }else{
            name = "null";
        }
        return name;
    }

    /**
     * 获取用户个人中心数据
     */
    public MutableLiveData<Resource<PersonCenterEntity.DataBean>> getPersonCenter(){
        MutableLiveData<Resource<PersonCenterEntity.DataBean>> liveData = new MutableLiveData<>();
        RequestParams params = new RequestParams();
        params.put("key","chargeEnable");
        RequestBody body = RequestBody.create(MediaType.parse("application/json;charset=UTF-8"), params.toString());
        return observeGo(RetrofitManager.getRetrofitManager().getRetrofit().create(MineApiService.class).getPersonCenter(body), liveData);
    }

    /**
     * 获取订单状态
     */
    public MutableLiveData<Resource<OrderEntity.DataBean>> getOrder(){
        MutableLiveData<Resource<OrderEntity.DataBean>> liveData = new MutableLiveData<>();
        return observeGo(RetrofitManager.getRetrofitManager().getRetrofit().create(MineApiService.class).getOrder(), liveData);
    }


    public void getUserAction(HttpCallBack<UserActionEntity> personCenterEntityHttpCallBack) {
        HttpUtils.post(MineApiService.getUserAction,personCenterEntityHttpCallBack);
    }

    public void getPersonCenterNew(HttpCallBack<PersonCenterEntity> personCenterEntityHttpCallBack) {
        RequestParams params = new RequestParams();
        params.put("key","chargeEnable");
        HttpUtils.post(MineApiService.personCenter,params,personCenterEntityHttpCallBack);
    }

    String isShowXx = "/vbp-patient/patient/isShowXx";
    public void isShowXx(String id,HttpCallBack<String> callBack) {
        RequestParams params = new RequestParams();
        params.put("passportId",id);
        HttpUtils.get(isShowXx,params,callBack);
    }

    String jumpUrl = "/vbp-patient/patient/jumpUrl";
    public void getJumpUrl(String passportId,HttpCallBack<String> httpCallBack){
        RequestParams params = new RequestParams();
        params.put("passportId",passportId);
        HttpUtils.get(jumpUrl,params,httpCallBack);
    }
}
